package com.hxzy.servlet.user;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author nick
 */
@WebServlet("/logout")
public class LogOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //立刻使服务器中的session失效
        HttpSession session = req.getSession(false);//如果不存在session，就不去创建新的session
        if (session != null) { //说明当前服务器中存在对应的session
            session.invalidate();//使session失效
        }

        //跳转到登录页
        resp.sendRedirect("login.jsp");

    }
}
